/*
 * File Name : shell_environment.cpp
 * Auther : dream.liuguobiao
 * Create Date : 2010-5-14
 * Last Edit : 2010-5-16
 */

#include "shell_environment.h"
#include "directory.h"

shell_environment *shell_environment::instance_shell_environment = NULL;

shell_environment::shell_environment()
:Linux_file_system( file_system::get_file_system() )
,all_users(users::get_users() )
,all_groups(groups::get_groups() )
{
  std::string name("root");
  user *root_user = new user( name ,0);
  root_user->set_password( &name );

  administrator = root_user;

  group *root_group = new group( name , 0);
  all_groups->insert_group( root_group );

  name = "dream";
  std::string tmp_string( "home");
  user *guest_user = new user ( name );
  guest_user->set_password( &name);
  all_users->insert_user( guest_user );
  file_system *my_file_system = file_system::get_file_system();
  node *current_node = my_file_system->get_current_directory();
  node *home = my_file_system->find_node_just_current_directory( &tmp_string);
  my_file_system->set_current_directory( home );
  
  node *dream_node = new directory();
  dream_node->set_name( &name);
  dream_node->set_userID( 500 );
  my_file_system->insert_node( dream_node);
  my_file_system->set_current_directory( current_node );
  
  root_user->insert_group( root_group );
  root_group->insert_user( root_user );
}

shell_environment *shell_environment::get_shell_environment(){
  if( 0 == instance_shell_environment ){
    instance_shell_environment = new shell_environment();
  }
  return instance_shell_environment;
}

file_system *shell_environment::get_file_system() 
{
 return Linux_file_system;
}

user *shell_environment::get_administrator()
{
 return administrator; 
}

users *shell_environment::get_all_users() 
{
 return all_users ; 
}

groups *shell_environment::get_all_groups()
{ 
return all_groups; 
}

std::stack<user*> *shell_environment::get_login_users() 
{
 return &login_users; 
}
